package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.common.Constants;
import com.macro.mall.config.CurrentUserInfo;
import com.macro.mall.dao.${EntityName}Dao;
import com.macro.mall.dto.${EntityName}QueryParam;
import com.macro.mall.dto.${EntityName}Vo;
import com.macro.mall.mapper.${EntityName}Mapper;
import com.macro.mall.model.${EntityName};
import com.macro.mall.model.${EntityName}Example;
import com.macro.mall.service.${EntityName}Service;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
* ${classDescription}Service
* Created by ${user} on ${date}.
*/
@Service
public class ${EntityName}ServiceImpl implements ${EntityName}Service {
    @Autowired
    private ${EntityName}Mapper ${entityName}Mapper;
    @Autowired
    private ${EntityName}Dao ${entityName}Dao;

    @Override
    public int create(${EntityName} ${entityName}) {
        ${entityName}.setCreateTime(DateTime.now().toDate());
        ${entityName}.setUpdateTime(DateTime.now().toDate());
        ${entityName}.setCreateUserId(CurrentUserInfo.getUserId());
        ${entityName}.setUpdateUserId(CurrentUserInfo.getUserId());
        ${entityName}.setStt(Constants.Stt.STT_INUSE);
        return ${entityName}Mapper.insert(${entityName});
    }

    @Override
    public int update(Long id, ${EntityName} ${entityName}) {
        ${entityName}.setId(id);
        return ${entityName}Mapper.updateByPrimaryKeySelective(${entityName});
    }

    @Override
    public int delete(List<Long> ids) {
        ${EntityName}Example example = new ${EntityName}Example();
        example.createCriteria().andIdIn(ids);
        return ${entityName}Mapper.deleteByExample(example);
    }

    @Override
    public List<${EntityName}> list() {
        ${EntityName}Example example = new ${EntityName}Example();
        return ${entityName}Mapper.selectByExample(example);
    }

    @Override
    public List<${EntityName}Vo> list(${EntityName}QueryParam ${entityName}QueryParam, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return ${entityName}Dao.selectiveList(${entityName}QueryParam);
    }
}
